/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package upr.daos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Claudivan Alves
 */
public class ConnectionFactory {
    private String url, driver, user, password;
    private static ConnectionFactory INSTANCE = null;

    private ConnectionFactory() {
        this.url = "jdbc:postgresql://localhost:5432/SIBI_UPR";
        this.driver = "org.postgresql.Driver";
        this.user = "postgres";
        this.password = "123456";
    }

    public static ConnectionFactory getInstance(){
        if (INSTANCE == null)
            INSTANCE = new ConnectionFactory();
        return INSTANCE;
    }

    public Connection getConnection() throws SQLException{
        try {
            Class.forName(this.driver);
            return DriverManager.getConnection(this.url, this.user, this.password);
        } catch (ClassNotFoundException ex) {
            System.out.println(ex.getMessage());
            throw new SQLException(ex.getMessage());
        }
    }
}
